package org.ax.service.process.imple;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.ax.mapper.process.TechnologyPlanMapper;
import org.ax.pojo.process.Technology;
import org.ax.pojo.process.TechnologyPlan;
import org.ax.service.process.TechnologyPlanService;
import org.ax.service.process.TechnologyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 编程人:赵浩鑫
 * 时间:2021-02-28-20:34
 */
@Service
public class ITechnologyPlanService extends ServiceImpl<TechnologyPlanMapper, TechnologyPlan> implements TechnologyPlanService {
    @Autowired
    TechnologyService technologyService;
    @Override
    public Page<TechnologyPlan> searchTechnologyPlanPage(Page page, String technologyId) {
        QueryWrapper<TechnologyPlan> queryWrapper=new QueryWrapper<TechnologyPlan>();
        queryWrapper.eq(!StringUtils.isBlank(technologyId),"technology_Id",technologyId);
        Page page1 = getBaseMapper().selectPage(page, queryWrapper);
        List<TechnologyPlan> technologyPlans=(List<TechnologyPlan>)page1.getRecords();
        for (TechnologyPlan technologyPlan : technologyPlans) {
            technologyPlan.setTechnology(technologyService.toTechnologyIdFind(technologyPlan.getTechnologyId()));
        }
        page1.setRecords(technologyPlans);
        return page1;
    }

    @Override
    public boolean addTechnologyPlan(TechnologyPlan technologyPlan) {
        return getBaseMapper().insert(technologyPlan)>0;
    }

    @Override
    public boolean updateTechnologyPlan(TechnologyPlan technologyPlan) {
        return getBaseMapper().updateById(technologyPlan)>0;
    }

    @Override
    public boolean deletesTechnologyPlan(String[] ids) {
        return getBaseMapper().deleteBatchIds(Arrays.asList(ids))>0;
    }
}
